home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-27 | 4.5 KB | 139 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- {UAssociation.p}
- {Copyright © 1988-1990 by Apple Computer Inc. All rights reserved}
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := FALSE}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT UAssociation;
-
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED __UAssociation__}
- {$SETC __UAssociation__ := FALSE}
- {$ENDC}
-
- {$IFC NOT __UAssociation__}
- {$SETC __UAssociation__ := TRUE}
-
- { • Auto-Include the requirements for this unit's interface }
- {$SETC UAssociationIncludes := UsingIncludes}
- {$SETC UsingIncludes := TRUE}
- {$I+}
- {$IFC UNDEFINED __UList__} {$I UList.p} {$ENDC}
- {$SETC UsingIncludes := UAssociationIncludes}
-
- TYPE
- TEntry = OBJECT (TObject) { This class has two instances variables to
- store a key string and an associated value
- string}
-
- fKey: StringHandle; { A handle to the 'keyStr'}
- fValue: StringHandle; { A handle to the 'valueStr'}
-
- PROCEDURE TEntry.IEntry(itsKey, itsValue: Str255);
- { Initialization routine}
-
- PROCEDURE TEntry.Free; OVERRIDE;
- { Frees the fKey & fValue string handles then calls inherited free}
-
- PROCEDURE TEntry.SetValue(VAR value: Str255);
- { Sets the fValue field to theValue}
-
- PROCEDURE TEntry.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields}
-
- END;
-
- TEntriesList = OBJECT (TSortedList) { Subclass of TSortedList that manages a
- sorted list of TEntry objects, used as an
- instance variable in TAssociation}
-
- PROCEDURE TEntriesList.IEntriesList;
- { Initialize the list }
-
- FUNCTION TEntriesList.Compare(item1, item2: TObject): INTEGER; OVERRIDE;
- { Compares 'item'1 with 'item2' returning an integer indicating the results of the
- comparison}
-
- PROCEDURE TEntriesList.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields }
-
- END;
-
- TAssociation = OBJECT (TObject) { This class is used to create lists of
- strings that are accessed via their
- associated keys. The keys & strings are
- stored in TEntry objects which are in the
- TEntriesList instance variable}
-
- fEntries: TEntriesList; { The list of TEntries that stores the
- associations }
-
- PROCEDURE TAssociation.IAssociation;
- { Initialization routine }
-
- PROCEDURE TAssociation.Free; OVERRIDE;
- { Frees the instance variable fEntries }
-
- FUNCTION TAssociation.ValueAt(keyStr: Str255;
- VAR valueStr: Str255): BOOLEAN;
- { Given 'keyStr' returns the associated string in 'valueStr', with the result true
- if an associated string was found }
-
- FUNCTION TAssociation.KeyAt(valueStr: Str255;
- VAR keyStr: Str255): BOOLEAN;
- { Given 'valueStr' returns the associated key in 'keyStr', with the result true if
- an associated key was found }
-
- PROCEDURE TAssociation.EachEntryDo(PROCEDURE
- DoToEntry(theEntry: TEntry));
- { Iterates over each entry passing it to "DoToEntry" }
-
- FUNCTION TAssociation.EntryWithKey(keyStr: Str255): TEntry;
- { Returns the Entry containing 'keyStr' }
-
- FUNCTION TAssociation.EntryWithValue(valueStr: Str255): TEntry;
- { Returns the entry containing 'valueStr' }
-
- FUNCTION TAssociation.FirstEntryThat(FUNCTION
- TestEntry(theEntry: TEntry): BOOLEAN): TEntry;
- { Iterates over each entry passing it to "TestEntry" until the result of the Test is
- TRUE }
-
- PROCEDURE TAssociation.InsertEntry(keyStr, valueStr: Str255);
- { Inserts an entry into thei association, if 'keyStr' already exists then the value
- is merely replaced with 'valueStr'. Otherwise a new Entry is created with the above
- 'keyStr' and 'valueStr' }
-
- PROCEDURE TAssociation.RemoveValueAt(keyStr: Str255);
- { Removes the value associated with 'keyStr' }
-
- PROCEDURE TAssociation.RemoveKeyAt(valueStr: Str255);
- { Removes the key associated with 'valueStr' }
-
- PROCEDURE TAssociation.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields }
-
- END;
-
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-